package com.caifeng.myapplication.login;

import android.graphics.Color;
import android.os.CountDownTimer;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.widget.TextView;

public class CountTimerUtils extends CountDownTimer {
    private TextView mTextview;

    public CountTimerUtils(long millisInFuture, long countDownInterval, TextView mTextview) {
        super(millisInFuture, countDownInterval);
        this.mTextview = mTextview;
    }


    @Override
    public void onTick(long millisUntilFinished) {
        mTextview.setClickable(false);
        mTextview.setTextColor(Color.GRAY);
        mTextview.setText(millisUntilFinished/1000 + "秒");


        SpannableString spannableString=new SpannableString(mTextview.getText().toString());
        ForegroundColorSpan span=new ForegroundColorSpan(Color.GRAY);
        spannableString.setSpan(span,0,2, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);

        mTextview.setText(spannableString);

    }

    @Override
    public void onFinish() {
        mTextview.setText("获取验证码");
        mTextview.setTextColor(Color.BLACK);
        mTextview.setClickable(true);

    }
}
